package com.example.springbook.controller;

import com.example.springbook.bean.User;
import com.example.springbook.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RestController
@RequestMapping(value = "/user")
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping(value = "/user",method = RequestMethod.POST)
    public boolean addUser(@RequestBody User user){
//        System.out.println("新增数据：");
        System.out.println("add data");
        return userService.addUser(user);
    }

    @RequestMapping(value = "/user",method = RequestMethod.PUT)
    public boolean updateUser(@RequestBody User user){
        System.out.println("更新数据：");
        return userService.updateUser(user);
    }

    @RequestMapping(value = "/user",method = RequestMethod.DELETE)
    public boolean delete(@RequestParam(value = "id",required = true) int id){
        System.out.println("删除数据：");
        return userService.deleteUser(id);
    }

    @RequestMapping(value = "/userAll",method = RequestMethod.GET)
    public List<User> findAllUser(){
//        System.out.println("查询所有数据：");
        System.out.println("findall");
        return userService.findAllUser();
    }

    @RequestMapping(value = "/login",method = RequestMethod.GET)
    public String selectUser(@RequestParam(value = "id",required = true) int id){
        System.out.println("selectUser");
        return userService.selectUser(id);
    }

    @RequestMapping(value = "/findName",method = RequestMethod.GET)
    public String findUserName(@RequestParam(value = "id",required = true) int id){
        System.out.println("findUserName");
        return userService.findUserName(id);
    }
}
